
const Koa = require('koa')
const logger = require('koa-logger')
const bodyParser = require('koa-bodyparser')
const cors = require('koa2-cors');
const registerRouter = require('./Server/routes/')
const err = require('./Server/middlreware/error')

const app = new Koa()
app.use(bodyParser())
app.use(cors())
app.use(logger())
app.use(err())
app
  .use(registerRouter())

app.listen(3000, () => {
  console.log(`自动部署服务器启动`)
})























// var http = require('http')
// var spawn = require('child_process').spawn
// // 脚本地址
// const script = './automaticDeployment.sh';
// // 执行指令的地址
// const currentPath = '/Users/duanpw/Desktop/部署/AutomaticDeployment/';
// const password = '1373513133';
// http.createServer(function (req, res) {
//   rumCommand('sh', [script], function( txt ) {
//     console.log(`在${currentPath}目录下执行了脚本${script}`);
//     console.log(txt);
//   });
//   return
//   if(req.headers['x-gitee-token'] === password) {
//     console.log('密码正确 开始拉取代码');
//     rumCommand('sh', [script], function( txt ) {
//       console.log(`在${currentPath}目录下执行了脚本${script}`);
//       console.log(txt);
//     });
//     res.statusCode = 200;
//     res.end('success');
//   } else {
//     res.statusCode = 200;
//     res.end('???');
//   }
// }).listen(3000);




// console.log('listen to 127.0.0.1:3000')

// function rumCommand( cmd, args, callback ) {
//   var child = spawn( cmd, args, {
//     cwd: currentPath,
//   } )
//   var response = ''
//   child.stdout.on('data', function( buffer ){
//    response += buffer.toString(); 
//   })

//   child.stdout.on('end', function(){ 
//     callback( response ) 
//   })
// }


